package com.example.fireDet.controller;

import com.example.fireDet.entity.ImageTrackTable;
import com.example.fireDet.model.FindByDate;
import com.example.fireDet.service.ImageTrackTableService;
import com.example.fireDet.serviceImpl.AWDMatchWebSocket;
import com.example.fireDet.serviceImpl.ImageTrackTableImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/back")
public class BackController {
    @Resource
    ImageTrackTableService imageTrackTableService;

    @Resource
    AWDMatchWebSocket webSocket;
    @PostMapping("/cam1")
    public String saveCam1(@RequestBody ImageTrackTable imageTrackTable){
        webSocket.sendOneMessage(1L,imageTrackTable.getImageLocation());
        System.out.println(imageTrackTable);
        imageTrackTableService.save(imageTrackTable);
        return "success";
    }
    @PostMapping("/cam2")
    public String saveCam2(@RequestBody ImageTrackTable imageTrackTable){
        webSocket.sendOneMessage(2L,imageTrackTable.getImageLocation());
        System.out.println(imageTrackTable);
        imageTrackTableService.save(imageTrackTable);
        return "success";
    }
    @PostMapping("/cam3")
    public String saveCam3(@RequestBody ImageTrackTable imageTrackTable){
        webSocket.sendOneMessage(3L,imageTrackTable.getImageLocation());
        System.out.println(imageTrackTable);
        imageTrackTableService.save(imageTrackTable);
        return "success";
    }
    @PostMapping("/cam4")
    public String saveCam4(@RequestBody ImageTrackTable imageTrackTable){
        webSocket.sendOneMessage(4L,imageTrackTable.getImageLocation());
        System.out.println(imageTrackTable);
        imageTrackTableService.save(imageTrackTable);
        return "success";
    }
    @PostMapping("/cam5")
    public String saveCam5(@RequestBody ImageTrackTable imageTrackTable){
        webSocket.sendOneMessage(5L,imageTrackTable.getImageLocation());
        System.out.println(imageTrackTable);
        imageTrackTableService.save(imageTrackTable);
        return "success";
    }
    @PostMapping("/cam6")
    public String saveCam6(@RequestBody ImageTrackTable imageTrackTable){
        webSocket.sendOneMessage(6L,imageTrackTable.getImageLocation());
        System.out.println(imageTrackTable);
        imageTrackTableService.save(imageTrackTable);
        return "success";
    }
    @PostMapping("/findByDate")
    @ResponseBody
    public List<ImageTrackTable> findById(@RequestBody FindByDate findByDate){
        System.out.println(findByDate);
        return imageTrackTableService.findByDate(findByDate);
    }
//    @PostMapping("/findByDate")
//    public String findById(@RequestBody FindByDate findByDate){
//        System.out.println(imageTrackTableService.findByDate(findByDate));
//        return "SUCCESS";}
}

